<?php
header('content-type:text/html; charset=utf-8');
session_start();



@$id=$_REQUEST['caiId'];
@$leiid=$_REQUEST['newleiId'];
@$name=$_REQUEST['name'];
@$price=$_REQUEST['price'];

@$src="";

if(empty($_FILES['file']['tmp_name'])){
	$src=$_REQUEST['originalFile'];
}else{
	if ($_FILES["file"]["error"] > 0)
	{
		header('content-type:text/html; charset=utf-8');
		header('Refresh:2;url=/cpl.php');
		die("上传错误: " . $_FILES["file"]["error"] . "<br />");
	}
	if (file_exists("img/" . $_FILES["file"]["name"]))
	{
		header('content-type:text/html; charset=utf-8');
		header('Refresh:2;url=/cpl.php');
		die($_FILES["file"]["name"] . " 此文件已经存在，请更换其他文件，或更改此文件的文件名。 ");
	}else{
		$src="img/" . $_FILES["file"]["name"];
		move_uploaded_file($_FILES["file"]["tmp_name"],	$src);
	
	}
}

$pdo=new PDO('mysql:dbname=can;charset=utf8','root');

$s=$pdo->prepare('update cai set name=:name,leiId=:newleiId,price=:price,src=:src where id=:caiId');
if($s->execute(array('name'=>$name,'caiId'=>$id,'price'=>$price,'newleiId'=>$leiid,'src'=>$src))){
	header('content-type:text/html; charset=utf-8');
	header('Refresh:2;url=/cpl.php');
	echo "ok";
}else {
	echo "error";
}
echo $src;


?>